#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <ctime>
#include "Blockqueue.hpp"

void *Consumer(void *args)
{
    Blockqueue<int> *bp = static_cast<Blockqueue<int> *>(args);
    int out = 0;
    while (true)
    {
        sleep(2);
        bp->pop(&out);
        std::cout << "Consumer : " << out << std::endl;
    }
}

void *Productor(void *args)
{
    srand(time(nullptr) ^ getpid());
    Blockqueue<int> *bp = static_cast<Blockqueue<int> *>(args);
    while (true)
    {
        sleep(1);
        int data = rand() % 10 + 1;
        bp->Equeue(data);
        std::cout << "Productor : " << data << std::endl;
    }
}

int main()
{
    Blockqueue<int> *bq = new Blockqueue<int>();
    pthread_t c, p;
    pthread_create(&c, nullptr, Consumer, (void *)bq);
    pthread_create(&p, nullptr, Productor, (void *)bq);

    sleep(100);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    return 0;
}